package controller

import (
	"exam_go/service"
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

type UserController struct {
}

func (u UserController) HandleLogin(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleLoginservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u UserController) HandleLogout(c *gin.Context) {
	userService := service.UserService{}
	err := userService.HandleLogoutservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
	})
}

func (u UserController) HandleGetSongInfo(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetMusicInfoservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u UserController) HandleSearchSongs(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleSearchSongsservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u UserController) HandleGetRecommend(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetPerRecommendservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u UserController) HandleGetRecommendByLanguage(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetRecommendByLanguageService(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}

func (u UserController) HandleGetHotArtists(c *gin.Context) {
	userService := service.UserService{}
	resp, err := userService.HandleGetHotArtistsservice(c)
	if err != nil {
		fmt.Printf("controller %v", err)
		c.Error(&gin.Error{
			Err:  err,
			Type: service.SysErr,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"data":    resp,
	})
}
